﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using VersionComparer.Comparer;
using VersionComparer.Configuration;
using VersionComparer.Images;

namespace VersionComparer.DataModel.Xml
{
    public class XmlAttributeItem : XmlItem
    {

        protected static Image attributeImage = InitializeImage(ImageResources.Attribute);
        
        public XmlAttributeItem()
        {
        }
        public XmlAttributeItem(ComparableItem parent, XmlNode node)
            : base(parent, node)
        {
        }
        protected override System.Drawing.Image GetImage()
        {
            return attributeImage;
        }
      
        public override double Matches(ComparisonAlgorithm algorithm, ComparableItem other)
        {
            if (Text != other.Text)
                return Match.NoMatch;
            if (other.FullText == FullText)
                return Match.CertainMatch;

            return Match.MatchStrings(algorithm , other.FullText, FullText, false);
        }

        protected override int CompareToItem(ComparableItem other)
        {
            XmlAttributeItem otherItem = other as XmlAttributeItem;
            return XmlNode.Name.CompareTo(otherItem.XmlNode.Name);
        }
        protected override void BuildRtf(Base.RtfBuilder builder, bool differencesOnly, bool useParentColor)
        {
            builder.Append(" " + XmlNode.Name, Color.Red,(Difference == DataModel.Difference.Value || Difference == DataModel.Difference.ValueCase) ? (Color?)Color.Empty: null);
            builder.Append("=\"", Color.Blue);
            /*if ( differencesOnly )
                SubItems[0].GetAsRtf(builder, differencesOnly);
            else
             * */
            GetChilds()[0].GetAsRtf(builder, differencesOnly, useParentColor);
            builder.Append("\"", Color.Blue);
        }
        /*
        protected override IComparableItem[] CreateChilds()
        {
            return new IComparableItem[] { new XmlAttributeValueItem(this, XmlNode) };
        }
         * */
        
    }
}
